/**
 * \file ThreadManager_Linux.h
 * \brief ThreadManager definition class for Linux platforms
 * \author Edouard ROGE
 * \date 29 august 2012
 */

#ifndef _THREADMANAGER_LINUX_
#define _THREADMANAGER_LINUX_

#include <vector>
#include "Core/Define/Define.h"
#include "Core/Pattern/Singleton.h"

class Thread;

/**
 * \class TaskManager
 * \brief class that manages the threads
 */
class ThreadManager : public Singleton<ThreadManager>
{
public:

	/**
	 * \fn ThreadManager();
	 * \brief Default Constructor
	 */
	ThreadManager();

	/**
	 * \fn virtual ~TaskManager();
	 * \brief Destructor
	 */
	virtual ~ThreadManager();

	/**
	 * \fn uint32 GetMaxThread() const;
	 * \return the number of the maximum thread
	 * \brief get the number of maximum thread that are able to run simultaneous
	 */
	uint32 GetMaxThread() const;

	/**
	 * \fn uint32 GetRunningThreads() const;
	 * \return the number of running threads
	 * \brief get the number of running threads
	 */
	uint32 GetRunningThreads() const;

	/**
	 * \fn void Register(Task * _pTask);
	 * \param _pTask task to register into the manager
	 * \brief register a task into the manager
	 */
	void Register(Thread * _pThread);

	/**
	 * \fn void Unregister(Task * _pTask);
	 * \param _pTask task to unregister
	 * \brief unregister a task from the manager
	 */
	void Unregister(Thread * _pThread);

	/**
	 * \fn void Clear();
	 * \brief Wait for all the running thread and unregister them
	 */
	void Clear();

private:

	/** Max thread number */
	static const uint32 MAX_THREAD=64;

	/** array of the tasks that are running */
	std::vector<Thread *> m_Threads;
};

#endif /* _THREADMANAGER_LINUX_ */

